package com.xingdata.jjxc.utils;

import android.graphics.Bitmap;
import android.util.LruCache;

/**
 * 图片缓存器
 * 
 * @author Administrator
 * 
 */
public class BitmapCache {
	// 获取应用的最大可用内存
	private static int maxMemory = (int) Runtime.getRuntime().maxMemory();
	// 设置LruCache缓存最大值
	private static int cacheMemory = maxMemory / 6;
	private static LruCache<String, Bitmap> lruCache = new LruCache<String, Bitmap>(
			cacheMemory);

	public static LruCache<String, Bitmap> getLruCache() {
		return lruCache;
	}

	public static void put(String key, Bitmap value) {
		if (value==null) {
			lruCache.remove(key);
		}else {
			lruCache.put(key, value);
		}
		
	}

	public static Bitmap get(String key) {
		if (lruCache.get(key) != null && lruCache.get(key).isRecycled()) {
			return null;
		} else {
			return lruCache.get(key);
		}

	}

}
